const {UserRole} = require("../db/seq")
const {Role} = require("../db/seq");

class UserRoleServe {


    async saveUserRoleServe(userId, roleId, createdByUserId) {
        const res = await UserRole.create({userId, roleId, createdByUserId})
        return res.dataValues;
    }

    async updateUserRoleServe(userId, roleId, createdByUserId) {
        const res = await UserRole.update({userId, roleId, createdByUserId}, {
            where: {
                userId
            }
        })
        return res[0] > 0;
    }

    async getUserRoleByIdServe(userId) {
        const res = await UserRole.findOne({
            where: {
                userId
            },
            attributes: {exclude: ['deletedTime', 'createdByUserId']},
        })
        return res ? res.dataValues : null
    }

    async getRoleListServe() {
        const res = await Role.findAll({
            attributes: {exclude: ['deletedTime', 'createdByUserId']},
        })
        return res ? res : null
    }
}

module.exports = new UserRoleServe();
